<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片上传测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .upload-section {
            border: 2px dashed #ccc;
            padding: 20px;
            margin: 20px 0;
            text-align: center;
        }
        .upload-section:hover {
            border-color: #007bff;
        }
        input[type="file"] {
            margin: 10px 0;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            margin: 5px;
        }
        button:hover {
            background-color: #0056b3;
        }
        .result {
            margin-top: 20px;
            padding: 10px;
            border-radius: 5px;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
    </style>
</head>
<body>
    <h1>图片上传测试页面</h1>
    
    <div class="upload-section">
        <h3>方法1: 使用 @RequestPart 注解</h3>
        <input type="file" id="file1" accept="image/*">
        <br>
        <button onclick="uploadImage1()">上传图片 (uploadImage)</button>
    </div>

    <div class="upload-section">
        <h3>方法2: 使用 @RequestParam 注解</h3>
        <input type="file" id="file2" accept="image/*">
        <br>
        <button onclick="uploadImage2()">上传图片 (uploadImage2)</button>
    </div>

    <div class="upload-section">
        <h3>方法3: 兼容性最好的方案</h3>
        <input type="file" id="file3" accept="image/*">
        <br>
        <button onclick="uploadImage3()">上传图片 (uploadImage3)</button>
    </div>

    <div id="result"></div>

    <script>
        function uploadImage1() {
            const fileInput = document.getElementById('file1');
            const file = fileInput.files[0];
            if (!file) {
                showResult('请选择文件', 'error');
                return;
            }
            
            const formData = new FormData();
            formData.append('flimage', file);
            
            fetch('/uploadImage', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                showResult('方法1结果: ' + JSON.stringify(data), data.success ? 'success' : 'error');
            })
            .catch(error => {
                showResult('方法1错误: ' + error.message, 'error');
            });
        }

        function uploadImage2() {
            const fileInput = document.getElementById('file2');
            const file = fileInput.files[0];
            if (!file) {
                showResult('请选择文件', 'error');
                return;
            }
            
            const formData = new FormData();
            formData.append('flimage', file);
            
            fetch('/uploadImage2', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                showResult('方法2结果: ' + JSON.stringify(data), data.success ? 'success' : 'error');
            })
            .catch(error => {
                showResult('方法2错误: ' + error.message, 'error');
            });
        }

        function uploadImage3() {
            const fileInput = document.getElementById('file3');
            const file = fileInput.files[0];
            if (!file) {
                showResult('请选择文件', 'error');
                return;
            }
            
            const formData = new FormData();
            formData.append('file', file); // 使用 'file' 作为参数名
            
            fetch('/uploadImage3', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                showResult('方法3结果: ' + JSON.stringify(data), data.success ? 'success' : 'error');
            })
            .catch(error => {
                showResult('方法3错误: ' + error.message, 'error');
            });
        }

        function showResult(message, type) {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = `<div class="result ${type}">${message}</div>`;
        }
    </script>
</body>
</html> 